package com.situ.mall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.situ.mall.common.exception.SituException;
import com.situ.mall.pojo.entity.user.User;
import com.situ.mall.user.mapper.UserMapper;
import com.situ.mall.user.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Sun Huijuan
 * @since 2024-10-14
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User login(User user) {
		QueryWrapper<User> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("name", user.getName());
		User loginUser = userMapper.selectOne(queryWrapper);
		//判断用户名是否存在
		if (loginUser == null) {
			throw new SituException("用户名不存在！");
		}
		//判断密码是否正确
		if (!loginUser.getPassword().equals(user.getPassword())) {
			throw new SituException("密码错误！");
		}
		if(loginUser.getStatus()==0){
			throw new SituException("该账号被禁用！");
		}
		//构建Token
		
		return loginUser;
	}
}
